package br.ufrj.dcc.gui;

import java.awt.BorderLayout;
import java.util.Vector;

import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import org.jgraph.JGraph;

import br.ufrj.dcc.engine.AppListener;
import br.ufrj.dcc.engine.Controller;

/**
* Standard basic view window, made with Jingloo.
* @author Pedro Rougemont
* 
*/
public class Vista extends JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.jgoodies.looks.plastic.Plastic3DLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/** Default serial number. */
	private static final long serialVersionUID = 1L;
	private JMenuBar menuBar;
	private JComboBox methodSelectionMenu;
	private JPanel parametersPane;
	private JButton executeButton;
	private JMenuItem openFileItem;
	private JMenu fileMenu;
	private Vector<String> methods;
	private JInternalFrame graphFrame;
	private JScrollPane graphScrollPane;
	private Controller controller;
	private AppListener appListener;
	private JGraph graph;
	
	/** Default constructor. 
	 * @param methods2 */
	public Vista(Controller controller, Vector<String> methods2) {
		super();
		this.controller = controller;
		this.methods = methods2;
		this.appListener = new AppListener(controller);
		initGUI();
	}
	
	/** GUI builder method. */
	private void initGUI() {
		try {
			BoxLayout thisLayout = new BoxLayout(getContentPane(), javax.swing.BoxLayout.X_AXIS);
			getContentPane().setLayout(thisLayout);
			{
				parametersPane = new JPanel();
				getContentPane().add(parametersPane);
				parametersPane.setPreferredSize(new java.awt.Dimension(170, 337));
				{
					ComboBoxModel methodSelectionMenuModel = 
						new DefaultComboBoxModel(methods);
					methodSelectionMenu = new JComboBox();
					parametersPane.add(methodSelectionMenu);
					methodSelectionMenu.setModel(methodSelectionMenuModel);
					methodSelectionMenu.setActionCommand("newMethodSelected");
					methodSelectionMenu.addActionListener(appListener);
				}
				{
					executeButton = new JButton();
					parametersPane.add(executeButton);
					executeButton.setText("Execute");
					executeButton.setSize(14, 7);
					executeButton.addActionListener(appListener);
					executeButton.setActionCommand("execute");
				}
			}
			{
				graphFrame = new JInternalFrame();
				getContentPane().add(graphFrame);
				graphFrame.setVisible(true);
				{
					graphScrollPane = new JScrollPane();
					graphFrame.getContentPane().add(graphScrollPane, BorderLayout.CENTER);
					graphScrollPane.setBounds(2, 0, 10, 10);
					
				}
			}
			{
				menuBar = new JMenuBar();
				setJMenuBar(menuBar);
				{
					fileMenu = new JMenu();
					menuBar.add(fileMenu);
					fileMenu.setText("File");
					{
						openFileItem = new JMenuItem();
						fileMenu.add(openFileItem);
						openFileItem.setText("Open File");
						openFileItem.setActionCommand("open");
						openFileItem.addActionListener(appListener);
					}
				}
			}
			{
				this.setSize(538, 421);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Vista instance = new Vista(null, new Vector<String>());
				instance.setLocationRelativeTo(null);
				instance.setVisible(true);
			}
		});
	}

	public void setGraph(JGraph graph) {
		this.graph = graph;
		graphScrollPane.setViewportView(graph);
		
	}
}
